#include <iostream>
using namespace std;

int converse(int b, int n)
{
	int tot = 0, t = 1;
	while (n--) {
		tot += t;
		t *= b;
	}
	return tot;
}

int main()
{
	int b, n;
	while (cin >> b >> n) {
		int num = converse(b, n);
		if (test(num)) cout << "YES" << endl;
		else		   cout << "NO" << endl;
		//cout << num << endl;
	}
	return 0;
}
